﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
//using System.Web.DynamicData;
using OA.Model;
using OA.Model.MyAttribute;
using OA.Core;

namespace OA.Model
{
    [Table("Employee")]
    public class Employee : BaseInfo
    {
        public int Status { get; set; }

        // [Index(name: "EmpID", IsClustered = false, IsUnique = true, Order = 1)]
        [Display(Name = "员工编号")]
        [MaxLength(10)]
        [Required(ErrorMessage = "不能为空")]
        [Tag(TagEnum.Text, "required", "员工编号",3,10)]
        public string EmpID { get; set; }


        [MaxLength(20)]
        [Display(Name = "姓名")]
        [Tag(TagEnum.Text, "required", "姓名", 2,20)]
        [Required]
        public string EmpName { get; set; }

        [Display(Name ="密码")]
        [MaxLength(32)]
        public string Password { get; set; }


        [Display(Name = "Token")]
        [MaxLength(32)]
        public string Token { get; set; }

        /// <summary>
        /// 姓名拼音
        /// </summary>
        [Required(ErrorMessage = "不能为空")]
        [Display(Name = "姓名拼音")]
        [MaxLength(50, ErrorMessage = "最大长度为50个字符")]
        [Tag(TagEnum.Text, "required", "姓名拼音", 3,50)]
        public string EmpName_PY { get; set; }

        /// <summary>
        /// 员工照片
        /// </summary>
        [Display(Name = "员工照片")]
        [MaxLength(100)]
        [Tag(TagEnum.SingleImageUpload, "required", "员工照片","")]
        public string Pic { get; set; }

        /// <summary>
        /// 入职时间
        /// </summary>
        [Display(Name = "入职时间")]
        [MaxLength(10)]
        [Tag(TagEnum.Date, "required", "入职时间","")]
        [Required]
        public string HireDate { get; set; }       
       
        /// <summary>
        /// 性别
        /// </summary>
        [Display(Name = "性别")]
        [Tag(TagEnum.Radio, "required", "性别", "男,女")]
        [Required]
        public string Sex { get; set; }

        /// <summary>
        /// 民族
        /// </summary>
        [Display(Name = "民族")]
        [Required(ErrorMessage = "不能为空")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        [Tag(TagEnum.Text, "required", "民族", 1,20)]
        public string Nation { get; set; }

        /// <summary>
        /// 出生时间
        /// </summary>
        [Display(Name = "出生时间")]
        [Required(ErrorMessage = "不能为空")]
        [MaxLength(10, ErrorMessage = "最大长度为10个字符")]
        [Tag(TagEnum.Date, "required", "出生时间",10,10)]
        public string Birthday { get; set; }

        /// <summary>
        /// 户籍所在地
        /// </summary>
        [Display(Name = "户籍所在地")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyProvince { get; set; }

        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyProvinceName { get; set; }

        /// <summary>
        /// 户籍所在地
        /// </summary>
        [Display(Name = "户籍所在地")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyCity { get; set; }

        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyCityName { get; set; }

        /// <summary>
        /// 户籍所在地
        /// </summary>
        [Display(Name = "户籍所在地")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyArea { get; set; }

        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        public string FamilyAreaName { get; set; }

        /// <summary>
        /// 常居住地
        /// </summary>
        [Display(Name = "常居住地")]
        [MaxLength(50, ErrorMessage = "最大长度为50个字符")]
        [Tag(TagEnum.Text, "required", "常居住地",0,50)]
        public string Address { get; set; }

        /// <summary>
        /// 是否统招
        /// </summary>
        [Display(Name = "是否统招")]
        [Column(TypeName = "bit")]
        [Tag(TagEnum.Switch, null, "required", "是否统招")]
        public bool NUEE { get; set; }


        /// <summary>
        /// 婚姻状态
        /// </summary>
        [Display(Name = "婚姻状态")]
        [Tag(TagEnum.Radio, "required", "婚姻状态", "未婚,已婚,离异,丧偶")]
        [MaxLength(4)]
        [Required]
        public string Marriage { get; set; }

        /// <summary>
        /// 身高
        /// </summary>
        [Display(Name = "身高")]
        [Tag(TagEnum.Number, "required", "身高", "")]
        public int Height { get; set; }

        /// <summary>
        /// 政治面貌
        /// </summary>
        [Display(Name = "政治面貌")]
        [Tag(TagEnum.Radio, "required", "政治面貌", "群众,团员,中共预备党员,中共党员,其他党派人士")]
        [Required]
        public string Politics { get; set; }

        /// <summary>
        /// 入党时间
        /// </summary>
        [Display(Name = "入党时间")]
        [MaxLength(4, ErrorMessage = "最大长度为4个字符")]
        [Tag(TagEnum.Year, "", "入党时间", 0,4)]
        public string JoinTime { get; set; }

        /// <summary>
        /// 组织关系何处
        /// </summary>
        [Display(Name = "组织关系何处")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        [Tag(TagEnum.Text, "", "组织关系何处", 0,20)]
        public string Organization { get; set; }

        /// <summary>
        /// 最高学历
        /// </summary>
        [Display(Name = "最高学历")]
        [Tag(TagEnum.Radio, "required", "最高学历", "小学,初中,高中,中专,职高,大专,本科,硕士,博士,博士后")]
        [Required]
        public string HighestEducation { get; set; }

        /// <summary>
        /// 毕业证类型
        /// </summary>
        [Display(Name = "毕业证类型")]
        [MaxLength(50)]
        [Tag(TagEnum.Radio, "required", "毕业证类型", "全日制,专升本,成人教育,自考,电大,网络教育,其他")]
        [Required]
        public string EducationType { get; set; }

        /// <summary>
        /// 毕业时间
        /// </summary>
        [Display(Name = "毕业时间")]
        [MaxLength(7, ErrorMessage = "最大长度为7个字符")]
        [Tag(TagEnum.YearMonth, "required", "毕业时间", 0,7)]
        public string GraduationDate { get; set; }

        /// <summary>
        /// 所学专业
        /// </summary>
        [Display(Name = "所学专业")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        [Tag(TagEnum.Text, "required", "所学专业","")]
        public string Specialty { get; set; }

        /// <summary>
        /// 毕业院校
        /// </summary>
        [Display(Name = "毕业院校")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        [Tag(TagEnum.Text, "required", "毕业院校", "")]
        public string School { get; set; }

        /// <summary>
        /// 身份证
        /// </summary>
        [Display(Name = "身份证")]
        [Required(ErrorMessage = "不能为空")]
        [MaxLength(18, ErrorMessage = "最大长度为18个字符")]
        [Tag(TagEnum.Text, "required|identity", "身份证",15,18)]
        public string SID { get; set; }

        /// <summary>
        /// 手机号码
        /// </summary>
        [Display(Name = "手机号码")]
        [Required(ErrorMessage = "不能为空")]
        [MaxLength(11, ErrorMessage = "最大长度为11个字符")]
        [Tag(TagEnum.Text, "required|phone", "手机号码", 11,11)]
        public string Telephone { get; set; }

        /// <summary>
        /// 电话保密
        /// </summary>
        [Display(Name = "电话保密")]
        [Tag(TagEnum.Switch, null, "required", "电话保密")]
        public bool TelIsSecrecy { get; set; }


        /// <summary>
        /// 推荐人
        /// </summary>
        [Display(Name = "推荐人")]
        [MaxLength(20, ErrorMessage = "最大长度为20个字符")]
        [Tag(TagEnum.Text, "", "推荐人", 0,20)]
        public string Referrer { get; set; }


        /// <summary>
        /// 邮箱
        /// </summary>
        [Display(Name = "邮箱")]
        [EmailAddress(ErrorMessage = "格式不正确")]
        [MaxLength(50, ErrorMessage = "最大长度为30个字符")]
        [Tag(TagEnum.Text, "required|email", "邮箱", 5,50)]
        [Required]
        public string Email { get; set; }
        

        /// <summary>
        /// 其他需说明的事项
        /// </summary>
        [Display(Name = "其他需说明的事项")]
        [MaxLength(500, ErrorMessage = "最大长度为500个字符")]
        [Tag(TagEnum.TextArea, "", "其他需说明的事项", 5, 20)]
        public string OtherDescription { get; set; }


        /// <summary>
        /// 短号
        /// </summary>
        [Display(Name = "手机短号")]
        [MaxLength(10, ErrorMessage = "最大长度为10个字符")]
        [Tag(TagEnum.Text, "", "手机短号", 1,10)]
        public string TelSimpleNum { get; set; }
        


        /// <summary>
        /// 头衔
        /// </summary>
        [Display(Name = "头衔")]
        [MaxLength(50)]
        [Tag(TagEnum.Text, "required", "头衔",0,50)]
        public string Honor { get; set; }
         

        [Display(Name = "排序")]
        [Tag(TagEnum.Number, "required", "排序", 0,100)]
        public int Sort { get; set; }


        /// <summary>
        /// 微信小程序openid
        /// </summary>
        [MaxLength(100)]
        public string Openid { get; set; }


        public DateTime? LockTime { get; set; }

        public int ErrorTimes { get; set; }

        /// <summary>
        /// 职层
        /// </summary>
        [MaxLength(20)]
        [Display(Name = "职层")]
        [Tag(TagEnum.Select, "required", "排序", 0, 100)]
        public string PositionLevel { get; set; }

        /// <summary>
        /// 虚拟级层，审批用。默认=虚拟职层
        /// </summary>
        [MaxLength(20)]
        [Display(Name = "虚拟职层")]
        [Tag(TagEnum.Select, "required", "排序", 0, 100)]
        public string VirtualPositionLevel { get; set; }

    } 

    public class Employee8
    {
        public int DepartmentID { get; set; }

        public string EmpID { get; set; }

        public string EmpName { get; set; }

        public string Honor { get; set; }

        public string Telephone { get; set; }

    }

    public class Employee9 : SimpleInfo
    {
        public string EmpID { get; set; }

        public string EmpName { get; set; }


        public static void SetPositionLevelID(string names,List<Employee9> list)
        {
            List<string> positionLevelNames = new List<string>();
            if(!string.IsNullOrWhiteSpace(names))
            {
                positionLevelNames = names.Split(new string[] { ",", "，" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }
            if (list == null || list.Count == 0) { return; }
            Dictionary<string, int> dic = new Dictionary<string, int>();
            for (int i=0;i< positionLevelNames.Count;i++)
            {
                if(!dic.ContainsKey(positionLevelNames[i]))
                {
                    dic.Add(positionLevelNames[i], i + 1);
                }
            }             
        }

        public static Expression<Func<Employee, Employee9>> Map = m => new Employee9()
        {
          EmpID=m.EmpID,
          EmpName=m.EmpName
        };
    }

    public class MyTree
    {
        public string t { get; set; }

        public string v { get; set; }

        /// <summary>
        /// 是否选中
        /// </summary>
        public int s { get; set; } = 0;

        public List<MyTree> d { get; set; }
    }


    public class SimpleEmployee : SimpleInfo
    {
        public string EmpID { get; set; }

        public string EmpName { get; set; }

        public string HireDate { get; set; }


        public string Sex { get; set; }


        public string Honor { get; set; }


        public string TelSimpleNum { get; set; }


        public string Email { get; set; }


        public string Telephone { get; set; }


        public string Birthday { get; set; }

        public string StatusName { get { if (this.Status == -1) { return "离职"; } else { return "在职"; }} }

        public static Expression<Func<Employee, SimpleEmployee>> Map = m => new SimpleEmployee()
        {
            ID = m.ID,
            Email=m.Email,
            Birthday=m.Birthday,
            EmpID=m.EmpID,
            EmpName=m.EmpName,
            HireDate=m.HireDate,
            Honor=m.Honor,
            Sex=m.Sex,
            Status=m.Status,
            Telephone=m.Telephone,
            TelSimpleNum=m.TelSimpleNum
        };

    }

    public class MyPosition
    {
        public int ID { get; set; }
        /// <summary>
        /// PositionName
        /// </summary>
        public string PositionName { get; set; }

        public string DepartmentName { get; set; }
  
        public int DepartmentID { get; set; }

    }


}